package thread;

import java.util.concurrent.atomic.AtomicInteger;

public class Counter implements Runnable{
    //private volatile Integer sum=0;
    private AtomicInteger sum=new AtomicInteger(0);
    public Counter(Integer i){
        //sum=i;
    }

    @Override
    public void run() {for(int i=0;i<1000;i++) {
        add();
//        try {
//            Thread.sleep(1);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
    }System.out.println(sum);
    }

     private void add(){

            //synchronized(this){
            //sum++;
           // }
         sum.incrementAndGet();


    }

    public static void main(String[] args) {
        Counter counter=new Counter(3000);
        Thread[] as= new Thread[10];
        for (int i=0;i<10;i++){
            as[i]=new Thread(counter);
        }
        for (int i=0;i<10;i++){
            as[i].start();
        }


//        Thread a=new Thread(counter);
//        Thread b=new Thread(counter);
//        Thread c=new Thread(counter);
//        Thread d=new Thread(counter);
//        a.start();
//        b.start();
//        c.start();
//        d.start();
    }

}
